package com.symria.server.bo.common;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.symria.framework.page.Page;
import com.symria.framework.util.Config;
import com.symria.framework.util.HttpClientUtils;
import com.symria.server.dao.common.IosDao;
import com.symria.server.http.bean.StringUtil;
import com.symria.server.po.IosActivate;
import com.symria.server.po.IosAdConfig;
import com.symria.server.po.IosChannelConfig;
import com.symria.server.po.IosClick;


public class IosService extends CommonService {
	
	private IosDao iosDao;
	public void searchAdConfig(IosAdConfig config,Page page){
		iosDao.searchAdConfig(config, page);
	}
	public void searchChannelConfig(IosChannelConfig config,Page page){
		iosDao.searchChannelConfig(config, page);
	}
	public IosDao getIosDao() {
		return iosDao;
	}
	public void setIosDao(IosDao iosDao) {
		this.iosDao = iosDao;
	}
	public void updateAdConfig(IosAdConfig c,IosAdConfig nc){
		if(StringUtil.isEmpty(c.getAppId())){
			c.setAppId(nc.getAppId());
		}
		c.setCheckMatch(nc.getCheckMatch());
		c.setClickUrl(nc.getClickUrl());
		c.setSource(nc.getSource());
		c.setStatus(nc.getStatus());
		c.setType(nc.getType());
		c.setSecond(nc.getSecond());
		updateObject(c);
		
		Map<String, String> param = new HashMap<String, String>();
		param.put("type","adconfig");
		param.put("key", c.getAppId());
		HttpClientUtils.readFromURL(Config.getValue("api.url"), param, null);
	}
	public void updateChannelConfig(IosChannelConfig c,IosChannelConfig nc){
		if(StringUtil.isEmpty(c.getChannel())){
			c.setChannel(nc.getChannel());
		}
		c.setActivateUrl(nc.getActivateUrl());
		c.setAppId(nc.getAppId());
		c.setCallBack(nc.getCallBack());
		c.setIdfa(nc.getIdfa());
		c.setMac(nc.getMac());
		c.setStatus(nc.getStatus());
		c.setRate(nc.getRate());
		updateObject(c);
		Map<String, String> param = new HashMap<String, String>();
		param.put("type","channelconfig");
		param.put("key", c.getChannel());
		HttpClientUtils.readFromURL(Config.getValue("api.url"), param, null);
	}
	public void searchIosClick(Page page,IosClick click,Date beginDate,Date endDate){
		iosDao.searchIosClick(page, click, beginDate, endDate);
	}
	public void searchIosActivate(Page page,IosActivate activate,Date beginDate,Date endDate){
		iosDao.searchIosActivate(page, activate, beginDate, endDate);
	}
	public List<IosAdConfig> queryAdConfig(){
		return iosDao.queryAdConfig();
	}
	public List<IosChannelConfig> queryChannelConfig(){
		return iosDao.queryChannelConfig();
	}
	public void searchIosDaily(Page page,String appId,String channel,Date beginDate,Date endDate){
		iosDao.searchIosDaily(page, appId, channel,beginDate,endDate);
	}
}
